package ch.ebnoether.player;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Frank
 * Date: 15.09.12
 * Time: 17:56
 * To change this template use File | Settings | File Templates.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "score", propOrder = {"player"})
@XmlRootElement(name = "score")
public class Score {

  @XmlElement(name = "player")
  private List<Player> player;

  public Score() {
  }

  public List<Player> getPlayerList() {
    if (player == null) {
      player = new ArrayList<Player>();
    }
    return player;
  }

  public void setPlayerList(List<Player> playerList) {
    this.player = playerList;
  }

  public boolean addNewPlayer(Player player) {
    return getPlayerList().add(player);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Score score = (Score) o;

    if (player != null ? !player.equals(score.player) : score.player != null) return false;

    return true;
  }

  @Override
  public int hashCode() {
    return player != null ? player.hashCode() : 0;
  }

  @Override
  public String toString() {
    String list = "";
    if (getPlayerList().size() > 0) {
      for (Player player : this.player) {
        if (player.getRang() < 10) {
          list += "  " + player.getRang() + ".) " + player.getPunkte() + " - " + player.getName() + "\n";
        } else {
          list += player.getRang() + ".) " + player.getPunkte() + " - " + player.getName() + "\n";
        }
      }
    }
    return list;
  }
}
